﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JohnHolliday.Caml.Net;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace Camelot
{
    public partial class SearchResults : BaseUserControl
    {
        public SearchResults()
        {
            InitializeComponent();
        }

        public void DisplayResults(SearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
            {
                throw new ArgumentNullException("searchCriteria");
            }

            if (searchCriteria.WebUrl == null)
            {
                throw new Exception("WebUrl can not be null");
            }

           
            using (SPSite site = new SPSite(searchCriteria.WebUrl.ToString()))
            using (SPWeb web = site.OpenWeb())
            {
                DataTable dataTable = web.GetSiteData(searchCriteria.GetQuery());
                this.dataGridView1.DataSource = dataTable;
            }            
        }       
    }
}
